package com.hxzy.tms.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hxzy.tms.dao.HibernateBaseDao;
import com.hxzy.tms.dao.UserDao;
import com.hxzy.tms.entity.User;

public class UserDaoImpl extends HibernateBaseDao<User> implements UserDao{
    private Logger logger=LoggerFactory.getLogger(getClass());

    public User get(String email) {
        Query query = getSession().createQuery("from User where email = :email");
        query.setString("email", email);
        @SuppressWarnings("unchecked")
        List<User> userList = query.list();
        if (userList == null || userList.isEmpty()) {
            return null;
        }
        if (userList.size() > 1) {
            logger.error("数据异常：到多个用户名为 {} 的用户。", email);
        }
        return userList.get(0);
    }

    public void saveOrUpdate(User user) {
        getSession().saveOrUpdate(user);
    }

}
